<?php

        
        
        
        
        class feature extends model {
           
           
           function add()
           {
           $productid="";
           
           if(is_numeric($this->info['parameter'][1]))
           {
           $productid=$this->info['parameter'][1];
           
           }
           if($this->info['config']['isinfo']==1)
           {
           
             $sql='SELECT
tb_product.productid
FROM
tb_plugins_infostant
INNER JOIN tb_product ON tb_plugins_infostant.productid = tb_product.productid
where tb_product.createby='.$this->userdata['userid'];


            $arrayset=$this->db->db_set_1recordrow($sql);
            if($arrayset['productid'])
            {
                $productid=$arrayset['productid'];
            
            }
            

            

           }
           
           
              $arraynewdata2=array();
             if($productid)
             {
             $userdata=$this->getuserbyoauth($this->userdata['oauth']);
             $limit="";
             $innerjoin="";
             $groupby="";
             $orderby="";
             $where='and createby='.$userdata['userid'];
             if($userdata['roleid']==3)
             {
             $where="";
             }
             $where="where productid=".$productid.' '.$where;
             $limit="limit  0,1";           
             $getproduct=$this->getproductbycondition($where,$limit,$orderby,$innerjoin,$groupby,'',1);
             
             if($getproduct[0]['productid'])
             {
             $arraynewdata2=$getproduct[0];
             
             }else
             {
             return false;
             }
             
             }

            
            $arraynewdata=array();           
            $arraynewdata=$this->memcache->get($this->info['config']['link'].'-'.$this->userdata['oauth'].'-'.$productid);
            
            if(count($arraynewdata)==0||$_GET['nocahce']==1)
            {
              
              foreach ($this->info['config']['plugins'] as $key => $row) {
              $volume[$key]  = $row['sort'];
              }
                 
              array_multisort($volume, SORT_ASC, $this->info['config']['plugins']);
              




              
              foreach($this->info['config']['plugins'] as $valueplugins)
              {
              if($valueplugins['show']==1)
              {
              
              eval("\$obj = new Plugins_".ucfirst($valueplugins['name']).'($this->db);');  
              $arraydata=$obj->getformadd();
              if(is_array($arraydata['form']))
              {
              $keydata=1;
              foreach($arraydata['form'] as $valueform)
              {
              
              
              
              $arraynewdata['formadd'][$valueplugins['name'].$keydata]=str_replace(array("\r", "\n", "\r"), '', $valueform);
              $keydata++;
              }
              
              $arraynewdata['formadd'][$valueplugins['name']]='<input type="hidden" value="'.$valueplugins['plugid'].'" name="plugid[]"><input type="hidden" value="'.$valueplugins['name'].'" name="plugname[]">';
              
              
              }else{
              $arraynewdata['formadd'][$valueplugins['name']]=str_replace(array("\r", "\n", "\r"), '', $arraydata['form']).'<input type="hidden" value="'.$valueplugins['plugid'].'" name="plugid[]"><input type="hidden" value="'.$valueplugins['name'].'" name="plugname[]">';
              }
              if($arraydata['js'])
              {
              
              $arraynewdata['jsadd'][$valueplugins['name']]=$arraydata['js'];
              }
              if($arraydata['css'])
              {
              
              $arraynewdata['cssadd'][$valueplugins['name']]=$arraydata['css'];
              }
              
              if($valueplugins['default']==1)
              {
              
              
               if($valueplugins['config'])
              {
              
              $arraynewdata['default'][$valueplugins['name']]=json_encode($valueplugins['config']);
              
              }else
              {
              $arraynewdata['default'][$valueplugins['name']]=$valueplugins['default'];
              }
              
              $arraynewdata['alwayshow'][$valueplugins['name']]=$valueplugins['alwayshow'];
              
              
              
              
              }
              
              if($valueplugins['icon']==1)
              {
              
              $arraynewdata['icon'][$valueplugins['name']]=$valueplugins['count'];
              $arraynewdata['iconname'][$valueplugins['name']]=$valueplugins['iconname'];
              
              }
              
             
              
               
              }
              
              
              
              }
              

             
             $arraynewdata['tag']=$this->gettagbyfid($this->info['config']['fid']);
             $arraynewdata['fid']=$this->info['config']['fid'];
             $arraynewdata['code']=$this->info['config']['code'];
             $arraynewdata['ispoi']=$this->info['config']['ispoi'];
             
             $arraynewdata['space']=$this->getspacedatabyuserid($this->userdata['userid']); 
             $arraynewdata['userspace']=$this->getusedspacedatabyuserid($this->userdata['userid']); 
             
             $arraynewdata['product']=$arraynewdata2;
             
             
             
//             echo "<pre>";
//             print_r($arraynewdata['product']);
//             echo "</pre>;";
//             exit;
             $arraynewdata['cssdata'][]=baseinfo.'/css/theme1/addcontent.css';
            

            
            
            $this->memcache->set($this->info['config']['link'].'-'.$this->userdata['oauth'].'-'.$productid,$arraynewdata);
            

           
            }
            
            
            
            
            
            
            $this->loadtemplate('addfeature',$arraynewdata);
            
            

           
           
           
           
           }
           
           function view(){ 



            if($this->info['parameter'][0]=="add"&&$this->userdata['oauth'])
            {
            
            if(is_array($this->info['config']['showwrite']))
            {

            
            
            if(@array_search($this->userdata['roleid'],$this->info['config']['showwrite'])!==false ){
            
            $this->add();
            
            }
            
            
            
            }else
            {
            
            $this->add();
            
            }

            
            
            }
            else if($this->info['parameter'][0]=="add")
            {
            

                $domain='';
               $time=time()+3600000;  
               setcookie("redirectto",$this->info['config']['link'].'/add', $time, "/",$domain); 
               header('Location: /login');
            
            }
            else if($this->info['parameter'][0]&&is_numeric($this->info['parameter'][1]))
            {

            $arraynewdata=array();
            

              $limit="";
              $innerjoin="";
              $groupby="";
              $orderby="";
              $arraydata=array();
             $where="where productid=".$this->info['parameter'][1];
             $limit="limit  0,1";           
             $getproduct=$this->getproductbycondition($where,$limit,$orderby,$innerjoin,$groupby,'',1);
            if($getproduct[0]['productid'])
            {
            
            if($getproduct[0]['status']=='2')
            {
            
            
             if($this->userdata['oauth'])
             {
             
             
             $userdata=$this->getuserbyoauth($this->userdata['oauth']);
            if($userdata['roleid']=='3'||$userdata['userid']==$getproduct[0]['createby'])
             {
             
             
             
             }else
             {
             
             
             exit;
             
             }
             
             
             }
            else
            {
            
            exit;
            }
            
            
            }
            
            
            
               $userdata=$this->getuserbyoauth($this->userdata['oauth']);
               if($userdata['userid'])
               {
                $arraydata4['createby']=$userdata['userid'];
               }
           
                $arraydata4['productid']=$getproduct[0]['productid'];
                
           
           
                $arraydata4['ip']=$_SERVER['REMOTE_ADDR'];
                $arraydata4['agent']=$_SERVER['HTTP_USER_AGENT'];
                $arraydata4['createdate']=date("Y-m-d H:i:s");
                $this->db->db_set($arraydata4,'tb_view');
                
               //echo "<pre>";
//               print_r($arraydata4);
//               echo "</pre>;";
                            
                             
            
            $arraydata['data']=$getproduct[0];
            
             $arraydata['bannerlandingset']= $this->getbannerlandingbyfid($arraydata['data']['fid']);
             
             
              
            
            
             //echo "<pre>";
//             print_r($arraydata['bannerlandingset']);
//             echo "</pre>;";
//             exit;
            //if(count($arraydata['data']))
            
//            echo "<pre>";
//            print_r($arraydata);
//            echo "</pre>;";
//            exit;
            $arraydata3=array(); 

            
            if(count($arraydata['data']['plugins']))
            {
                  foreach($arraydata['data']['plugins'] as $valueplugins)
                  {
                  
                      eval("\$obj = new Plugins_".ucfirst($valueplugins['plugname']).'($this->db);'); 
                      $arraydata3=$obj->getformlanding($valueplugins);
                      $arraydata[$arraydata3['target']][]=$arraydata3['str'];
                      
                      if($arraydata3['target2'])
                      {
                      
                      $arraydata[$arraydata3['target2']][]=$arraydata3['str2'];
                      }
                      if($arraydata3['script'])
                      {
                      $arraydata['script'][]=$arraydata3['script'];
                      
                      }
                      
                     
                  }
                  
            }
            $tagarr=array();
            if($arraydata['data']['tag'])
            {
            foreach($arraydata['data']['tag'] as $valuetag)
            {
            $tagarr[]=$valuetag['name'];
            
            
            }
            }
            $arraydata['data']['keyword']=join(",",$tagarr);
            
            $arraydata['otherproduct']=$this->getotherlandingbyuserid($getproduct[0]['createby']);
            $arraydata['relateproduct']=$this->getrelatebyproductid($arraydata4['productid']);
            
            
           //  echo "<pre>";
             //                print_r($getproduct[0]['feature']['isinfo']);
               //              echo "</pre>;";
                 //            exit;
            if(isset($getproduct[0]['feature']['isinfo'])&&$getproduct[0]['feature']['isinfo']=='1')
            {

                  if($arraydata['data']['plugins'][0]['path'])
                  {
                      $data['data']=$arraydata['data']; 
                      include(rootpath.'/templates/shop/'.$arraydata['data']['plugins'][0]['path'].'/index.php');
                  }
                   
            }else
            {
                $this->loadtemplate('landing',$arraydata);
            
            }                 
            
            
            
            

            
            }
            else
            {
                   include(rootpath.'/templates/shop/coffee/index.php');  
            
            }
            
            

            }
            else if($this->info['parameter'][0]&&$this->info['parameter'][1]&&$this->info['parameter'][2])
            {
            
            
            
            
            
            }
            else
            {
            

            $arraynewdata['fid']=$this->info['config']['fid'];
            $arraynewdata['featurename']=$this->info['config']['name'];
            
            $page=1;
          if($_GET['page'])
          {
          $page=$_GET['page'];

          }
          
          
          $arraynewdata['sitemap']=$this->getproductbyconditionshort($page,0,$arraynewdata['fid']);
            
            
            $this->loadtemplate('submain',$arraynewdata);  
            
            
            }
           
           
           
           }
        
        
        }
?>
